1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Array.prototype.pop = function () { let O = Object(this); let len = this.length >>> 0; if (len === 0) { O.length = 0; return undefined; } len--; let value = O[len]; delete O[len]; O.length = len; return value; };
Array.prototype.map = function (callbackFn, thisArg) { if (this === null || this === undefined) { throw new TypeError("Cannot read property 'map' of null"); } if (Object.prototype.toString.call(callbackfn) != "[object Function]") { throw new TypeError(callbackfn + " is not a function"); } let O = Object(this); let T = thisArg;
let len = O.length >>> 0; let A = new Array(len); for (let k = 0; k < len; k++) { if (k in O) { let kValue = O[k]; let mappedValue = callbackfn.call(T, KValue, k, O); A[k] = mappedValue; } } return A; };
Array.prototype.reduce = function (callbackfn, initialValue) { if (this === null || this === undefined) { throw new TypeError("Cannot read property 'reduce' of null"); } if (Object.prototype.toString.call(callbackfn) != "[object Function]") { throw new TypeError(callbackfn + " is not a function"); } let O = Object(this); let len = O.length >>> 0; let k = 0; let accumulator = initialValue; if (accumulator === undefined) { for (; k < len; k++) { if (k in O) { accumulator = O[k]; k++; break; } } } for (; k < len; k++) { if (k in O) { accumulator = callbackfn.call(undefined, accumulator, O[k], O); } } return accumulator; };
|